/*
    Random SBOX Generator !
    Author: @5mukx
*/

use std::collections::HashSet;
use rand::{rngs::StdRng, Rng, SeedableRng};

fn generate_sbox(seed: u64) -> [u8; 256]{
    let mut sbox = [0u8; 256];
    let mut used = HashSet::new();
    let mut rng = StdRng::seed_from_u64(seed);

    for i in 0..256{
        let mut value;
        loop{
            value = rng.gen_range(0..=255);
            if !used.contains(&value){
                used.insert(value);
                break;
            }
        }
        sbox[i] = value;
    }
    sbox
}

pub fn print_sbox(sbox: &[u8; 256]) {
    println!("static SBOX: [u8; 256] = [");
    for (i, value) in sbox.iter().enumerate() {
        if i % 16 == 0 {
            print!("    ");
        }
        print!("{:3},", value);
        if i % 16 == 15 {
            println!();
        }
    }
    println!("];");
}

fn main(){
    let seed = 12232;
    let sbox = generate_sbox(seed);

    print_sbox(&sbox);
}